{extend name="public/base" /}
{block name="style"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/bootstrap-editable.css">
<link rel="stylesheet" href="__PUBLIC__/admin/gzh/css/list.css?v=20221110&times={:time()}" />
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/iconfont.css" />
<link rel="stylesheet" href="__PUBLIC__/plugs/bootstrap-select/css/bootstrap-select.css"> <!--下拉框搜索引用css-->

{include file="material/_ali_icon" /}
<style>
    .main-box-body .navs .active {
        background: azure;
        color: #03a9f4;
        border: 1px solid #03a9f4;
        border-radius: 5px;
    }

    a {
        color: #777;
        text-decoration: none;
    }

    a:hover {
        text-decoration: none
    }

    .table tbody>tr>td {
        padding: 3px 8px;
    }

    .table-hover>tbody>tr:nth-child(odd) {
        background-color: #f9f9f9;
    }

    .table-responsive {
        min-height: 470px;
    }
</style>
<style>
    .uploadify-button-text {
        position: relative;
        display: inline-block;
        cursor: pointer;
        background: #fff;
        padding: 0px 5px;
        color: #333;
        text-align: center;
        border-radius: 3px;
        overflow: hidden;
        border: 1px solid #ccc;
    }

    em {
        color: red;
    }
</style>
{/block}
{block name="body"}
<div class="main-box clearfix">
    <header class="main-box-header clearfix">
        <div class="pull-right">
            <button type="button" class="btn btn-warning"> <input class="checkbox check-all" type="checkbox"
                    style="display: inline-block;margin-top: -2px;vertical-align: middle;"> 全选 </button>
            <!-- <button type="button" class="btn btn-warning"> <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;"> 全选 </button> -->
            <button type="button" class="btn btn-primary" id="createUrl">
                <i class="fa fa-plus"></i> 添加 <span class="caret"></span>
            </button> <button class="btn btn-danger ajax-post confirm"
                url="http://testadmin.ksyuedu.com/admin/material/del.html" target-form="ids">删 除</button>
        </div>
        <div class="row">
            <form method="get">

                <style>
                    @media (min-width: 1200px) {
                        .col-lg-1 {
                            width: 7.5%;
                        }
                    }
                </style>
                <div class="col-sm-12 col-md-4 col-lg-2">
                    <input type="text" class="form-control" name="keyword" value="" placeholder="请输入关键字搜索">
                </div>

                <div class="col-sm-12 col-md-1" style="width: 59px;">
                    <button class="btn btn-primary" type="submit">搜索</button>
                </div>

                <div class="col-sm-12 col-lg-1">
<!--                    class="selectpicker" 必须 data-live-search="true"  搜索才加-->
                    <select name="operate" id="operate" class="selectpicker" data-live-search="true">
                        <option value="0">全部运营员</option>
                        {foreach name="userlist" item="vo" key="k" }
                        <option value="{$k}" {if input('get.operate')==$k}selected {/if}>{$vo}</option>
                        {/foreach}
                    </select>
                </div>

                <div class="col-sm-12 col-lg-1">
                    <select name="channel" id="channel" class="form-control">
                        <option value="999999">频道</option>
                        <option value="1" {if input('get.channel')==1}selected {/if}>男频</option>
                        <option value="2" {if input('get.channel')==2}selected {/if}>女频</option>
                    </select>
                </div>

<!--                <div class="col-sm-12 col-lg-1">-->
<!--                    <select name="category_id" id="category_id" class="form-control">-->
<!--                        <option value="0">小说分类</option>-->
<!--                        <option value="999999">全部</option>-->
<!--                        <option value="39">玄幻</option>-->
<!--                        <option value="40">都市</option>-->
<!--                        <option value="41">灵异</option>-->
<!--                        <option value="42">历史</option>-->
<!--                        <option value="43">脑洞</option>-->
<!--                        <option value="44">古言</option>-->
<!--                        <option value="45">现言</option>-->
<!--                        <option value="46">年代</option>-->
<!--                        <option value="47">灵异</option>-->
<!--                        <option value="48">现实</option>-->
<!--                    </select>-->
<!--                </div>-->

<!--                <div class="col-sm-12 col-lg-1">-->
<!--                    <select id="pub_sort" class="form-control">-->
<!--                        <option value="1">按时间排序</option>-->
<!--                        <option value="4">复制从高到低</option>-->
<!--                        <option value="5">复制从低到高</option>-->
<!--                        <option value="2">评分从高到低</option>-->
<!--                        <option value="3">评分从低到高</option>-->

<!--                        <option value="6">加入从高到低</option>-->
<!--                        <option value="7">加入从低到高</option>-->

<!--                        <option value="8">量级从高到低</option>-->
<!--                        <option value="9">量级从低到高</option>-->
<!--                    </select>-->
<!--                </div>-->
                <div class="col-sm-12 col-lg-1">
                    <select id="pub_sort" class="form-control">
                        <option value="1"  {if input('get.pub_sort')==1}selected {/if}>按认证时间排序</option>
                        <option value="2"  {if input('get.pub_sort')==2}selected {/if}>认证时间从高到低</option>
                        <option value="3"  {if input('get.pub_sort')==3}selected {/if}>认证时间从低到高</option>
                        <option value="4"  {if input('get.pub_sort')==4}selected {/if}>粉丝数从高到低</option>
                        <option value="5"  {if input('get.pub_sort')==5}selected {/if}>粉丝数从低到高</option>
                    </select>
                </div>


            </form>
        </div>
    </header>
    <div class="main-box-body clearfix">
        <!-- 搜索相关 -->
        <div id="" class="clear"></div>
        <div class="table-responsive clearfix">
            <div class="table-responsive clearfix">
                <table class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th width="45px">序号</th>
                            <th width="100px">名字</th>
                            <th width="120px">账号</th>
                            <th width="120px">密码</th>
                            <th width="180px">邮箱</th>
                            <th width="150px">邮箱密码</th>
                            <th width="330px">原始ID/appid</th>
                            <th width="80px">用户属性</th>
                            <th width="80px">风格</th>
                            <th width="80px">粉丝数</th>
                            <th width="80px">主体</th>
                            <th width="80px">绑定书城</th>
                            <th width="80px">管理员</th>
                            <th width="100px">认证时间</th>
                            </th>
                            <th width="120px">操作</th>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                    {empty name="list"}
                    <tr><td colspan="9" align="center">暂无数据</td></tr>
                    {/empty}
                    {volist name="list" id="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td style="font-size: 17px;">{$vo.name}</td>
                            <td>{$vo.account}</td>
                            <td>{$vo.password}</td>
                            <td>{$vo.email}</td>
                            <td>{$vo.email_password}</td>
                            <td>
                                {$vo.originalid} <br>
                                {$vo.appid}
<!--                                <br>3456lfm123456</td>-->
                            <td>{$vo.channel == 1 ? '男' : '女'}</td>
                            <td>{$vo.style}</td>
                            <td>{$vo.fans_num}</td>
                            <td>{$vo.subject}</td>
                            <td>{$vo.binding}</td>
                            <td>{$vo.admin}</td>
                            <td>{$vo.auth_date}</td>
                            <td>
<!--                                <a href="#" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>-->
<!--                                <a href="JavaScript:;" onclick="editreferral(this)"><i class="fa fa-edit"></i>修改</a>-->
                                {if checkAuthRule('admin/gzh/del',false)}<a href="{:url('del',array('id'=>$vo['id'],'type'=>'list'))}" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>{/if}
                                <!--<a href="{:url('del',array('id'=>$vo['id']))}" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>-->
                                <a href="JavaScript:;" onclick="editreferral(this)" data-json='{:json_encode($vo)}'><i class="fa fa-edit"></i> 修改</a>
                            </td>
                        </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>

        </div>
    </div>
</div>
{$page}
<div class="modal fade" id="create-referral-link-modal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <span style="font-size: 20px;"><span id="referralname">添加</span></span>
            </div>
            <div class="modal-body">
                <div data-bind="visible: loading" class="loading-panel" style="display: none;">
                    <i class="fa fa-spin fa-spinner"></i>
                </div>
                <form class="form-horizontal modelform">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">名字</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="name">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">账号</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="account">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">密码</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="password">
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">邮箱</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="email">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">邮箱密码</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="email_password">
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">原始ID</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="originalid">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">APPID</label></label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="appid">
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">风格</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="style">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">粉丝数</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="fans_num">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">主体</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="subject">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">绑定书城</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="binding">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">管理员</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="admin">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-sm-3">运营专员</label>
                                <div class="col-lg-8">
                                    <select name="operate" id="operateSelect" class="selectpicker" data-live-search="true">
                                        <option value="0">全部运营员</option>
                                        {foreach name="userlist" item="vo" key="k" }
                                        <option value="{$k}">{$vo}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-sm-2" style="width:76px">用户属性</label>
                                <div class="col-lg-8">
                                   <label class="radio-inline">
                                       <input type="radio" name="channel" value="1">
                                       <span>男</span>
                                   </label>
                                   <label class="radio-inline">
                                       <input type="radio" name="channel" value="2">
                                       <span>女</span>
                                   </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="id">
                </form>
            </div>
            <div class="modal-footer">

                <button type="button" id="createreferral" class="btn btn-primary ">提交</button>
            </div>
        </div>
    </div>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/bootstrap-select/js/bootstrap-select.js"></script>

<script type="text/javascript">

        var url;
        $('#createUrl').on('click', function () {
            $("#referralname").html("添加");
            var $modal = $('#create-referral-link-modal');
            $modal.modal({backdrop: 'static', keyboard: false});
        });

    // 新增
    $("#createreferral").on('click',function(){
        url = "{:url('add')}"
        var data = $('.modelform').serializeJson();
        if ( data['name'] == undefined) {
            updateAlert("名字不能为空", 'danger');
            return false;
        }

        if (data['account'] == '') {
            updateAlert("账号不能为空", 'danger');
            return false;
        }
        console.log(data)
        $.ajax({
            type: "POST",
            url: url,
            data:data,
            dataType: "json",
            success: function(data){
                if(data.code==1){
                    updateAlert(data.msg, 'success');
                    setTimeout(function() {
                        window.location.reload();
                    }, 100);
                }else{
                    updateAlert("添加，"+data.msg, 'danger');
                }
            },
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        })
    });


    //编辑功能
    function editreferral(ee, rule=''){
        var is_rule = '{:checkAuthRule("admin/gzh/edit",false)}';
        console.log(is_rule);
        url = "{:url('edit')}"
         if(!is_rule && rule!='close_rule'){
             layer.msg("你没权限编辑");
             return;
         }

        $("#batchtxt").remove();
        var jsonStr = $(ee).attr('data-json');
        var $modal = $('#create-referral-link-modal');
        $modal.on('show.bs.modal', function () {
            $("#referralname").html("修改");
            var json =  eval("(" + jsonStr + ")");
            console.log(json)

            $('#createspreadid').val(json.id);
            $("input[name='name']").val(json.name);
            $("input[name='account']").val(json.account);
            $("input[name='password']").val(json.password);
            $("input[name=email]").val(json.email);
            $("input[name=originalid]").val(json.originalid);
            $("input[name=appid]").val(json.appid);
            $("input[name=auth_date]").val(json.auth_date);
            $("input[name=binding]").val(json.binding);
            $("input[name=email_password]").val(json.email_password);
            $("input[name=fans_num]").val(json.fans_num);
            $("input[name=style]").val(json.style);
            $("input[name=subject]").val(json.subject);
            $("input[name=admin]").val(json.admin);
            $("select[name=operate][id=operateSelect]").selectpicker('val', json.operate);
            //搜索
            $("input[name=id]").val(json.id);
            $("input:radio[name=channel][value="+json.channel+"]").attr("checked",true);
            // $("input:radio[name=category_id][value="+json.category_id+"]").attr("checked",true);
            // $("input:radio[name=book_id][value="+json.book_id+"]").attr("checked",true);
            // $("input:radio[name=magnitude_num][value="+json.magnitude_num+"]").attr("checked",true);
            // multipleInput(json.platform_ids.split(','),$("input:checkbox[name=platform_ids]"))
            // multipleInput(json.tag_ids.split(','),$("input:checkbox[name=tag_ids]"))
            // multipleInput(json.hot.split(','),$("input:checkbox[name=hot]"))

        });
        $modal.on('hide.bs.modal', function () {
            window.location.reload();
        })
        $modal.modal({backdrop: 'static', keyboard: false})
    }

    // 筛选框
    $(() => {
        
        // 运营专员 下拉可搜索
        $("#operate").on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
            search()
        });

        //频道
        $('#channel').change(() => {
            search()
        });

        //下拉排序
        $('#pub_sort').change(() => {
            search()
        });

        function search(){
            let searchUrl = `?operate=${$("#operate").val()}&channel=${$('#channel').val()}&pub_sort=${$('#pub_sort').val()}`
            window.location.href= searchUrl
        }
    });
</script>

{/block}